<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              onClick: handleView.bind(null, record),
              auth: 'order:refund:view',
            },
          ]"
        />
      </template>
    </BasicTable>
    <RefundOrderDrawer @register="registerDrawer" @success="reload"/>
  </div>
</template>
<script lang="ts">
  import {defineComponent} from 'vue';

  import {BasicTable, useTable, TableAction} from '/@/components/Table';

  import {useDrawer} from '/@/components/Drawer';
  import RefundOrderDrawer from './RefundOrderDrawer.vue';

  import {columns, searchFormSchema} from './refund.data';
  import {pageList} from './refund.api';

  export default defineComponent({
    name: 'RefundOrderManagement',
    components: {BasicTable, TableAction, RefundOrderDrawer},
    setup() {
      const [registerTable, {reload}] = useTable({
        title: '退款订单列表',
        api: pageList,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          slots: {customRender: 'action'},
          fixed: undefined,
        },
      });

      const [registerDrawer, {openDrawer}] = useDrawer();

      function handleView(record: Recordable) {
        openDrawer(true, {record});
      }

      return {
        registerTable,
        reload,
        registerDrawer,
        handleView,
      };
    },
  });
</script>
